package com.wsb.wetchat.service.impl;

import com.wsb.wetchat.service.ThreadPoolService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author wang shaobo
 * @date 2022/6/29  15:51
 */
@Service
public class ThreadPoolServiceImpl implements ThreadPoolService {


    @Override
    @Async("asyncExector")
    public void exectAsync(String str) {
        String name = Thread.currentThread().getName();
        System.out.println(name + "开始执行异步任务：参数:" + str);

        try{
            TimeUnit.SECONDS.sleep(5);
        }catch (Exception e){

        }
        System.out.println(name + "开始执行异步任务：参数:" + str+",执行完毕");
//        return "异步任务执行完毕:"+str;
    }


    @Override
    public String exectSync(String str) {
        String name = Thread.currentThread().getName();
        System.out.println(name + "开始执行同步任务：参数:" + str);

        return "同步任务执行完毕:"+str;
    }
}
